<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="w"%>
<%String path=request.getContextPath(); %>
<script>
function floorquerypro(){
	$("#channelProductstb").datagrid("load",{"bean.like":$getByName("proname",$w.currWin()).val(),"bean.rows":100})
}
function channelpromoveR(){
	var boxs=$("#channelProductstb").datagrid('getChecked');
	var selds=$("#channelProductsedtb").datagrid('getRows');
	for(var i=0;i<boxs.length;i++){
		var add=true;
		for(var n=0;n<selds.length;n++){
			if(selds[n].idcode==boxs[i].idcode){
				add=false;
				break;
			}
		}
		if(add){
			$('#channelProductsedtb').datagrid('insertRow',{
				index: 0,	// index start with 0
				row: {
					idcode: boxs[i].idcode,
					fullname: boxs[i].fullname,
					productcode:boxs[i].productcode
				}
			});
		}
	}
}
function channelpromoveL(){
	var selds=$("#channelProductsedtb").datagrid('getChecked');
	var n=selds.length;
	for(var i=0;i<n;i++){
		var index=$("#channelProductsedtb").datagrid('getRowIndex',selds[0].idcode);
		$("#channelProductsedtb").datagrid('deleteRow',index);
	}
}
function saveFlooritrmSubmit(){
	var selds=$("#channelProductsedtb").datagrid('getRows');
	var proids="";
	for(var i=0;i<selds.length;i++){
		if(proids!="")proids+=",";
		proids+=selds[i].idcode;
	}
	$getByName("bean.proids",$w.currWin()).val(proids);
	$w.doWinForm();
}
function seltop(){
    var selds=$("#channelProductsedtb").datagrid('getChecked');
    var n=selds.length;
    var sels=[];
    for(var i=0;i<n;i++){
        sels.push({idcode:selds[0].idcode,fullname:selds[0].fullname,productcode:selds[0].productcode})
        var index=$("#channelProductsedtb").datagrid('getRowIndex',selds[0].idcode);
        $("#channelProductsedtb").datagrid('deleteRow',index);
    }
    for(var i=0;i<sels.length;i++){
        $('#channelProductsedtb').datagrid('insertRow',{
            index: 0,	// index start with 0
            row: {
                idcode: sels[i].idcode,
                fullname: sels[i].fullname,
                productcode:sels[i].productcode
            }
        });
    }

}
function selup(){
    var selds=$("#channelProductsedtb").datagrid('getChecked');
    var n=selds.length;
    var sels=[];
    if(n>0){
        var index=$("#channelProductsedtb").datagrid('getRowIndex',selds[0].idcode);
        if(index<=0)return;
        for(var i=0;i<n;i++){
            sels.push({idcode:selds[0].idcode,fullname:selds[0].fullname,productcode:selds[0].productcode})
            index=$("#channelProductsedtb").datagrid('getRowIndex',selds[0].idcode);
            $("#channelProductsedtb").datagrid('deleteRow',index);
        }
        $("#channelProductsedtb").datagrid('uncheckAll');
        for(var i=(sels.length-1);i>=0;i--){
            $('#channelProductsedtb').datagrid('insertRow',{
                index: index-1,
                row: {
                    idcode: sels[i].idcode,
                    fullname: sels[i].fullname,
                    productcode:sels[i].productcode
                }
            });
            $("#channelProductsedtb").datagrid('checkRow',index-1);
        }

    }
}
function seldown(){
    var selds=$("#channelProductsedtb").datagrid('getChecked');
    var n=selds.length;
    var sels=[];
    var rnum=$("#channelProductsedtb").datagrid('getRows').length;
    if(n>0){
        var index=$("#channelProductsedtb").datagrid('getRowIndex',selds[n-1].idcode);
        if(index>=(rnum-1))return;
        for(var i=0;i<n;i++){
            sels.push({idcode:selds[0].idcode,fullname:selds[0].fullname,productcode:selds[0].productcode})
            index=$("#channelProductsedtb").datagrid('getRowIndex',selds[0].idcode);
            $("#channelProductsedtb").datagrid('deleteRow',index);
        }
        $("#channelProductsedtb").datagrid('uncheckAll');

        for(var i=(sels.length-1);i>=0;i--){
            $('#channelProductsedtb').datagrid('insertRow',{
                index: index+1,	// index start with 0
                row: {
                    idcode: sels[i].idcode,
                    fullname: sels[i].fullname,
                    productcode:sels[i].productcode
                }
            });
            $("#channelProductsedtb").datagrid('checkRow',index+1);
        }
    }
}
function selbottom(){
    var selds=$("#channelProductsedtb").datagrid('getChecked');
    var n=selds.length;
    var sels=[];
    for(var i=0;i<n;i++){
        sels.push({idcode:selds[0].idcode,fullname:selds[0].fullname,productcode:selds[0].productcode})
        var index=$("#channelProductsedtb").datagrid('getRowIndex',selds[0].idcode);
        $("#channelProductsedtb").datagrid('deleteRow',index);
    }
    var rnum=$("#channelProductsedtb").datagrid('getRows').length;

    for(var i=(sels.length-1);i>=0;i--){
        $('#channelProductsedtb').datagrid('insertRow',{
            index: rnum,	// index start with 0
            row: {
                idcode: sels[i].idcode,
                fullname: sels[i].fullname,
                productcode:sels[i].productcode
            }
        });
    }
}
</script>
<div class="easyui-panel" data-options="doSize:false,layoutH:47,border:false" style="margin:5px">
	<form method="post" action="/floor/FloorPage@floorCategorSave.page" class="pageForm">
		<w:hidden bind="bean.id"/>
		<w:hidden bind="bean.floorid"/>
		<w:hidden bind="bean.proids"/>
		<div class="ui-formContent">
			<p style="float:left">
				<label style="width:80px;text-align:right">类目名称：</label>
				<w:text bind="bean.name" style="width:300px;"/>
			</p>
			<p style="float:left">
				<label style="width:100px;text-align:right">排序号：</label>
				<w:text bind="bean.orderno" styleClass="easyui-numberbox" style="width:200px;"/>
			</p>
			<table cellpadding="0" cellspacing="0">
				<tr>
				<td valign="top" style="padding-top:4px;"><label style="width:80px;text-align:right">添加商品：</label></td>
				<td valign="top" style="padding-top:4px;padding-left:4px;">
					<div style="width:310px;border:1px solid #ddd;height:26px;line-height:26px;background:#fff"><input name="proname" style="display:inline-block;border:0px;margin:0px;width:260px;height:20px;"><a href="javascript:floorquerypro();" style="display:inline-block;float:right;height:26px;background:#F3F3F4;width:40px;color:#666666;text-align:center;font-size:18px;"><i class="fa fa-search"></i></a></div>
					<div style="width:310px;border:1px solid #ddd;border-top:none">
						<table id="channelProductstb" class="easyui-datagrid" style="width:310px;height:320px"  
					        data-options="url:'<%=path %>/products/ProductPage@loadProductPrices.page?rows=20&bean.status=2',fitColumns:true,multiple: true,idField:'idcode',
					        singleSelect:false,border:false,checkbox:true,pagination:false">  
						    <thead>  
						        <tr>  
						        	<th data-options="field:'idcode',checkbox:true"></th> 
						            <th data-options="field:'fullname',width:310">商品名称</th>  
						            <th data-options="field:'productcode'">编码</th>
						        </tr>  
						    </thead>  
						</table> 
					</div> 
				</td>
				<td width="50" align="center">
					<p><a href="javascript:void(0);" class="ui_btn" id="channelimgbtn" onclick="channelpromoveR()">></a></p>
					<p><a href="javascript:void(0);" class="ui_btn" id="channelimgbtn" onclick="channelpromoveL()"><</a></p>
					<p>&nbsp;</p>
				</td>
				<td valign="top" style="padding-top:4px;padding-left:4px;">
					<div style="width:310px;border:1px solid #ddd;margin-top:28px;">
					<table id="channelProductsedtb" class="easyui-datagrid" style="width:310px;height:320px"  
					        data-options="url:'<%=path %>/floor/FloorPage@loadFloorProducts.page?rows=200&bean.itemid=<w:write bind="bean.id"/>',fitColumns:true,multiple: true,idField:'idcode',
					        singleSelect:false,border:false,checkbox:true,pagination:false">  
					    <thead>  
					        <tr>  
					            <th data-options="field:'idcode',checkbox:true"></th> 
					            <th data-options="field:'fullname',width:310">商品名称</th>  
					            <th data-options="field:'productcode'">编码</th>
					        </tr>  
					    </thead>  
					</table> 
					</div>
				</td>
					<td width="50" align="center" style="padding-left:6px">
						<p><a href="javascript:void(0);" class="ui_btn" onclick="seltop()">最顶</a></p>
						<p><a href="javascript:void(0);" class="ui_btn" onclick="selup()">上移</a></p>
						<p><a href="javascript:void(0);" class="ui_btn" onclick="seldown()">下移</a></p>
						<p><a href="javascript:void(0);" class="ui_btn" onclick="selbottom()">最尾</a></p>
					</td>
				</tr>

			</table>
			<br/>
		</div>
	</form>
</div>
<div class="ui-buttonBar">
	<a href="javascript:;" class="easyui-linkbutton marginR16" iconCls="icon_save" onclick="saveFlooritrmSubmit()">保 存</a>
	<a href="javascript:;" class="easyui-linkbutton" iconCls="icon_cancel" onclick="$w.closeCurrWin()">取 消</a>
</div>
